const path = require("path");

module.exports = {
  publicPath: "/",
  outputDir: "dist",
  assetsDir: "static",
  productionSourceMap: false,
  configureWebpack: {
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
        "@public": path.resolve(__dirname, "public"),
      },
    },
    output: {
      filename: "static/js/[name].[hash].js",
      chunkFilename: "static/js/[name].[hash].js",
    },
  },
  css: {
    loaderOptions: {
      less: {
        lessOptions: {
          javascriptEnabled: true,
        },
      },
    },
    extract: {
      filename: "static/css/[name].[hash].css",
      chunkFilename: "static/css/[name].[hash].css",
    },
  },
  devServer: {
    port: 8080,
    open: true,
    proxy: {
      "/api": {
        target: process.env.VUE_APP_API_BASE_URL || "http://localhost:3000",
        changeOrigin: true,
        pathRewrite: {
          "^/api": "/api",
        },
      },
    },
  },
  chainWebpack: (config) => {
    config.plugin("copy").tap(([pathConfigs]) => {
      pathConfigs.unshift({
        from: "public",
        to: "public",
        toType: "dir",
        ignore: [".DS_Store"],
      });
      return [pathConfigs];
    });
  },
};
